import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_redux_hooks/flutter_redux_hooks.dart';
import 'package:wy/pages/account/login/login_1.dart';
import 'package:wy/pages/account/login/login_2.dart';
import 'package:wy/pages/account/login/login_3.dart';
import 'package:wy/pages/account/login/login_4.dart';
import 'package:wy/pages/account/login/login_5.dart';
import 'package:wy/store/store.dart';

class LoginPage extends HookWidget {
  const LoginPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final args = ModalRoute.of(context).settings.arguments;
    final dispatch = useDispatch<StoreState>();

    var step = 1;
    if (args != null) {
      step = (args as Map)['step'];
    }
    final steps = {
      1: LoginPage1(
        onLogin: () {
          Navigator.pushNamed(context, '/login', arguments: {
            'step': 2,
          });
        },
        onCancel: () {},
        onWechat: () {},
        onQQ: () {},
        onWeibo: () {},
        onApple: () {},
        onEasy: () {},
      ),
      2: LoginPage2(
        onNext: (curArea, text) {
          Navigator.pushNamed(context, '/login', arguments: {
            'step': 3,
          });
        },
      ),
      3: LoginPage3(
        onFinished: (val) {
          Navigator.pushNamed(context, '/login', arguments: {
            'step': 4,
          });
        },
      ),
      4: LoginPage4(onSubmit: (val) {
        print(val);
        Navigator.pushNamed(context, '/login', arguments: {
          'step': 5,
        });
      }),
      5: LoginPage5(onSubmit: (nickname) {
        dispatch(StoreAction(StoreActionType.UserLogin, nickname));
        // 完成注册
        Navigator.pushNamed(context, '/user-center');
      })
    };

    return steps[step];
  }
}
